"""
World of the game
"""

import mjin2
from GameObject import *
from GamePlayer import *
from GameScene import *

class World(GameObject):
    scenes = { }
    def __init__(self, application, pathResolver):
        super(World, self).__init__(pathResolver)
        self.player = GamePlayer(application)
    def finish(self):
        print "Finishing the world"
        super(World, self).finish()
    def finishScene(self, name):
        self.scenes[name].finish()
    def load(self, fileName):
        print "Loading world: {0}".format(fileName)
        # Parse World XML.
        xml = mjin2.XML()
        node = xml.load(self.pathResolver.findFile(fileName))
        w = node.nodes[0]
        if (w.name == "World"):
            for c in w.nodes:
                if ((c.name == "OnStart") or
                    (c.name == "OnFinish")):
                    self.addListener(c.name, c.nodes[0].value)
                elif (c.name == "Scene"):
                    fileName = c.nodes[0].value
                    print "Scene found: {0}".format(fileName)
                    self.scenes[fileName] = GameScene(self, fileName)
    def start(self):
        print "Starting the world. Addr: {0}".format(super(World, self).start)
        super(World, self).start()
    def startScene(self, name):
        print "World: starting the scene {0}".format(name)
        self.scenes[name].start()
